package org.easy.tool.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.easy.tool.common.LogUtil;
import org.easy.tool.common.TimeUtil;
import org.easy.tool.entity.Mark;
import org.easy.tool.mapper.MarkMapper;
import org.easy.tool.service.IMark;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * 标签服务实现类
 *
 * @author Valley
 * @since 2024-09-04 22:51:14
 */
@Service
public class MarkService extends ServiceImpl<MarkMapper, Mark> implements IMark {

    @Override
    public LinkedHashMap submitMark(LinkedHashMap data) throws Exception {
        LinkedHashMap res = new LinkedHashMap();
        String title = (String) data.get("title");
        for (Mark mark : list()) {
            if (mark.getTitle().equals(title)) {
                res.put("status", false);
                res.put("msg", "标签不允许重名");
                return res;
            }
        }
        String color = (String) data.get("color");
        Mark mark = new Mark();
        mark.setTitle(title);
        mark.setColor(color);
        mark.setCreateTime(TimeUtil.now());
        mark.setUpdateTime(TimeUtil.now());
        boolean save = save(mark);
        LogUtil.info("submitMark", save, mark);
        res.put("status", true);
        return res;
    }

    @Override
    public List<Mark> getMarkList(LinkedHashMap data) {
//        List<String> filterList = (List<String>) data.get("filterList");
        List<Mark> list = list();
        return list;
    }

    @Override
    public Mark getMarkByTitle(String title) {
        LambdaQueryWrapper<Mark> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Mark::getTitle, title);
        return getOne(wrapper);
    }
}
